<?php

	include ('../Model/item.class.php'); 
	include ('../Config/conn.php'); 

	$categoria = isset($_POST['categoria']) ? $_POST['categoria'] : '';
	$nome_item = isset($_POST['nome_item']) ? $_POST['nome_item'] : '';
			
	
	$ObjItem = new Item($db, 0, $categoria, $nome_item, 0);
	$last_row = $ObjItem->insereItem($db);	

	session_start();
	$idUser = $_SESSION['idUsuario'];
	
	// Replica a img				   
	include '../lib/wideimage/WideImage.php'; 
	
	$source = '../Temp/'.$idUser.'_newItem.jpg';
	$imgPath = '../Content/itens/'.$last_row.'.jpg';
	
	$originalImage = WideImage::load($source);
	$originalImage->saveToFile($imgPath);
	
	include ('../Config/destruct.php');
?>